package com.bite.principle.component;

import com.bite.principle.model.Dog;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BeanLifeComponent implements BeanNameAware {

    private Dog singletonDog;

    public BeanLifeComponent() {
        System.out.println("执行构造函数...");
    }

    @Autowired
    public void setSingletonDog(Dog singletonDog) {
        this.singletonDog = singletonDog;
        System.out.println("执行setSingletonDog....");
    }


    @Override
    public void setBeanName(String name) {
        System.out.println("setBeanName: "+name);
    }

    @PostConstruct
    public void init(){
        System.out.println("执行PostConstruct...");
    }

    public void use(){
        System.out.println("执行use方法....");
    }

    @PreDestroy
    public void destroy(){
        System.out.println("执行destroy方法");
    }
}
